//
//  main.m
//  OC_12月6日_练习
//
//  Created by dllo on 15/12/5.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        
        /** 数组 */
        /** 创建 */
#if 0
        NSArray *arr1 = [[NSArray alloc] initWithObjects:@"dalian", @"beijing", nil];
        NSArray *arr2 = [NSArray arrayWithObjects:@"dalian", @"hailin", nil];
        NSArray *arr3 = @[@"shanghai", @"dalian"];
        
        /** 获取元素个数 */
        NSArray *arr1 = @[@"dalian", @"bei", @"hailin"];
        
        NSLog(@"%ld", arr1.count);
        
        /** 获取指定下标对象 */
        
        NSString *str = [arr1 objectAtIndex:1];
        NSLog(@"%@", str);
        
        NSString *str1 = arr1[0];
        NSLog(@"%@", str1);
        
        /** 判断数组中是否包含某一个对象 */
        NSArray *arr = @[@"dalian", @"beijing", @"hailin"];
        if ([arr containsObject:@"aa"]) {
            NSLog(@"包含");
        } else {
            NSLog(@"NO");
        }
       
        /** 获取元素对应的下标 */
        NSArray *arr = @[@"dalian", @"hailin", @"beijing"];
        NSLog(@"%ld",[arr indexOfObject:@"hailin"]);
        
        /** 按照给定的字符串进行截取，将截取的多段字符串放入数组中 */
        NSString *str = @"http://www.kengni.com";
        NSArray *arr1 = [str componentsSeparatedByString:@"."];
        NSLog(@"%@", arr1);
        
        /** 将数组中的元素按照给定的字符串格式拼接成一个完整的字符串对象 */
        NSArray *arr = @[@"dalian", @"beijing", @"hailin"];
        NSString *str = [arr componentsJoinedByString:@".."];
        NSLog(@"%@", str);
        
        
        /** 存在如下字符串, 将其中的图片的网址取出来
         * http://www.imanhua.com/Cover/2011-10/hyrz.jpg&http://www.imanhua.com/Cover/2011-09/op.jpg&http://www.imanhua.com/Cover/2012-04/yjdwb.jpg */
        NSString *str1 = @"http://www.imanhua.com/Cover/2011-10/hyrz.jpg&http://www.imanhua.com/Cover/2011-09/op.jpg&http://www.imanhua.com/Cover/2012-04/yjdwb.jpg";
        NSArray *arr2 = [str1 componentsSeparatedByString:@"&"];
        NSLog(@"%@", arr2);
        
        /** 有如下一个数组，@[@“type = iOS", @"Device = iPhone", @"count = 11344115@163.com", @"password = 12345”]，将其中的内容用”&"符号拼接成一个字符串 */
        NSArray *arr = @[@"type = iOS", @"Device = iPhone", @"count = 11344115@163.com", @"password = 12345"];
        NSString *str = [arr componentsJoinedByString:@"&"];
        NSLog(@"%@", str);
#endif
#if 0
        /** 可变数组 */
        /** 创建对象 */
        NSMutableArray *mArr = [[NSMutableArray alloc] initWithObjects:@"dalian", @"hailin", @"USA", nil];
        NSMutableArray *mArr2 = [NSMutableArray arrayWithObjects:@"doupo", @"ashuai", @"wudong", nil];
        NSMutableArray *mArr3 = @[@"dalian", @"hailin", @"beijing"].mutableCopy;
        
        /** 数组中添加一个对象 */
        NSMutableArray *mArr = @[@"dalian", @"hailin", @"pinghe"].mutableCopy;
        [mArr addObject:@"hanguo"];
        NSLog(@"%@", mArr);
        
        /** 数组中指定位置插入一个对象 */
        [mArr insertObject:@"USA" atIndex:0];
        NSLog(@"%@", mArr);
        
        /** 数组中移除一个对象 */
        NSMutableArray *mArr = @[@"dalian", @"hailin", @"riben"].mutableCopy;
        [mArr removeObject:@"riben"];
        NSLog(@"%@", mArr);
        
        /** 移除数组中最后一个对象 */
        NSMutableArray *mArr = @[@"dalian", @"hailin", @"riben"].mutableCopy;
        [mArr removeLastObject];
        NSLog(@"%@", mArr);
        
        /** 移除数组中所有的元素 */
        [mArr removeAllObjects];
        NSLog(@"%@", mArr);
        
        /** 数组中移除指定位置的元素 */
        NSMutableArray *mArr = @[@"dalian", @"riben", @"hailin"].mutableCopy;
        [mArr removeObjectAtIndex:1];
        NSLog(@"%@", mArr);
        
        /** 使用指定的对象替换指定位置的对象 */
        NSMutableArray *mArr = @[@"dalian", @"beijing", @"hailin"].mutableCopy;
        [mArr replaceObjectAtIndex:2 withObject:@"USA"];
        NSLog(@"%@", mArr);
        
        /** 交换(exchange)指定的两个下标对应的对象 */
        [mArr exchangeObjectAtIndex:0 withObjectAtIndex:1];
        NSLog(@"%@", mArr);
#endif
        /** 不可变字典 */
        /** 创建对象 */
#if 0
        NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:@"wangqiang", @"name", @"20", @"age", nil];
        NSDictionary *dic2 = [NSDictionary dictionaryWithObjectsAndKeys:@"wangqiang", @"name", @"20", @"age", nil];
        NSDictionary *dic3 = @{@"name" : @"wangqiang", @"age" : @"80"};
        
        /** 获取字典中键值对的个数 */
        NSLog(@"%ld", dic.count);
        
        /** 获取字典中所有的键 */
        NSLog(@"%@",[dic allKeys]);
        
        /** 获取字典中所有的值 */
        NSLog(@"%@", [dic allValues]);
#endif
        /** 可变字典 */
        /** 创建对象 */
#if 0
        NSMutableDictionary *mDic = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"wangqiag", @"name", @"80", @"age", nil];
        NSMutableDictionary *mDic2 = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"wangyan", @"name", @"30", @"age", nil];
        NSMutableDictionary *mDic3 = @{@"name" : @"wangyan", @"age" : @"50"}.mutableCopy;
        
        /** 创建空字典 */
        NSMutableDictionary *mDic4 = [NSMutableDictionary dictionary];
        NSMutableDictionary *mDic5 = [NSMutableDictionary dictionaryWithCapacity:20];
        
        /** 字典中添加新的键值对以及 修改某一对键值对 */
        [mDic setObject:@"baketball" forKey:@"hobby"];
        NSLog(@"%@", mDic);
        
        /** 移除指定的键对应的键值对 */
        [mDic2 removeObjectForKey:@"age"];
        NSLog(@"%@", mDic2);
        
        /** 移除字典中所有的键值对 */
        [mDic3 removeAllObjects];
        NSLog(@"%@", mDic3);
#endif
#if 0
        /** 集合 */
        /** 创建 */
        NSSet *set = [[NSSet alloc] initWithObjects:@"gaoshou", @"heiliu", @"wangyan", nil];
        NSSet *set1 = [NSSet setWithObjects:@"wangqiang", @"wangyan", nil];
        
        /** 个数 */
        NSLog(@"%ld", [set count]);
        
        /** 取出对象 */
        NSLog(@"%@",[set anyObject]);
        
        /** 取出所有对象 */
        NSLog(@"%@", [set allObjects]);
        
        /** 判断是否含有某一个对象 */
        if ([set1 containsObject:@"wangyan"]) {
            NSLog(@"含有");
        } else {
            NSLog(@"不含有");
        }
        
        /** 可变集合 */
        /** 创建对象 */
        NSMutableSet *mSet = [[NSMutableSet alloc] initWithObjects:@"zhang", @"wang", @"li", nil];
        NSMutableSet *mSet1 = [NSMutableSet setWithObjects:@"zhang", nil];
        
        /** 添加对象 */
        [mSet addObject:@"hei"];
        NSLog(@"%@", mSet);
        
        /** 移除对象 */
        [mSet removeObject:@"hei"];
        NSLog(@"%@", mSet);
        
        /** 移除所有 */
        [mSet removeAllObjects];
        
#endif
        
        
        /** 快速遍历数组 */
        NSMutableArray *mArr = @[@"wangqiang", @"zhangqiang", @"liqiang"].mutableCopy;
        for (NSString *str in mArr) {
            NSLog(@"%@", str);
        }
        
        /** 快速遍历字典 */
        NSMutableDictionary *mDic = @{@"name" : @"wangqiang", @"age" : @"30"}.mutableCopy;
        for (NSString *key in mDic) {
            NSLog(@"%@", [mDic objectForKey:key]);
        }
        
        /** 快速遍历集合 */
        NSMutableSet *mSet = [NSMutableSet setWithObjects:@"wang", @"zhang", @"li", nil];
        for (NSString *str2 in mSet) {
            NSLog(@"%@", str2);
            }
        
        
        
        int a[6] = {1, 2, 3, 5, 4 ,6};
        int count = sizeof(a) / sizeof(a[0]);
        for (int i = 0; i < count - 1; i++) {
            for (int j = 0; j < count - i - 1; j++) {
                if (a[j] > a[j + 1]) {
                    int temp = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = temp;
                }
            }
        }
        
        for (int i = 0; i < count; i++) {
            NSLog(@"a[%d] = %d", i, a[i]);
        }
        
        
        
        
        
        
        
        
        
        
        
        
        
        
    }
    return 0;
}
